<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>{{ site_name() }} - 管理后台</title>
    
    <!-- Google Fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    
    <!-- Font Awesome -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    
    <!-- Vite Assets -->
    @vite(['resources/sass/app.scss', 'resources/js/app.js'])
    
    <style>
        :root {
            --sidebar-width: 280px;
            --header-height: 70px;
        }

        * {
            box-sizing: border-box;
        }

        body {
            font-family: 'Inter', sans-serif;
            background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
            min-height: 100vh;
            margin: 0;
            padding: 0;
        }

        /* 主容器 - 使用 Flexbox 布局 */
        .admin-container {
            display: flex;
            min-height: 100vh;
            width: 100%;
        }

        /* 侧边栏样式 */
        .sidebar {
            width: var(--sidebar-width);
            min-width: var(--sidebar-width);
            max-width: var(--sidebar-width);
            height: 100vh;
            background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
            backdrop-filter: blur(20px);
            border-right: 1px solid rgba(255, 255, 255, 0.1);
            z-index: 1000;
            overflow-y: auto;
            overflow-x: hidden;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            flex-shrink: 0;
            position: sticky;
            top: 0;
        }

        .sidebar-header {
            padding: 1.5rem;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }

        .sidebar-header h5 {
            color: #ffffff;
            font-weight: 700;
            font-size: 1.25rem;
            margin: 0;
            background: linear-gradient(135deg, #ffffff, #e2e8f0);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .sidebar-header small {
            color: #94a3b8;
            font-size: 0.875rem;
            font-weight: 500;
            display: block;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            margin-top: 0.25rem;
        }

        .sidebar-nav {
            padding: 1rem 0;
        }

        .nav-item {
            margin: 0.25rem 1rem;
        }

        .nav-link {
            color: #94a3b8;
            padding: 0.875rem 1rem;
            border-radius: 0.75rem;
            font-weight: 500;
            font-size: 0.95rem;
            text-decoration: none;
            display: flex;
            align-items: center;
            transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
            position: relative;
            overflow: hidden;
            white-space: nowrap;
            min-height: 48px;
            width: 100%;
            box-sizing: border-box;
        }

        .nav-link:hover {
            color: #ffffff;
            background: rgba(5, 150, 105, 0.2);
            transform: translateX(4px);
        }

        .nav-link.active {
            color: #ffffff;
            background: #008080;
            box-shadow: 0 4px 12px rgba(5, 150, 105, 0.3);
        }

        .nav-link i {
            margin-right: 0.875rem;
            font-size: 1.1rem;
            width: 20px;
            text-align: center;
            flex-shrink: 0;
        }

        .nav-link span {
            flex: 1;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            font-weight: 500;
        }

        .nav-link::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 0;
            height: 100%;
            background: linear-gradient(135deg, rgba(5, 150, 105, 0.15), rgba(5, 150, 105, 0.1));
            transition: width 0.3s ease;
            border-radius: 0.75rem;
        }

        .nav-link:hover::before {
            width: 100%;
        }

        .nav-divider {
            height: 1px;
            background: rgba(255, 255, 255, 0.1);
            margin: 1rem 1.5rem;
        }

        /* 主内容区域 - 自适应布局 */
        .main-content {
            flex: 1;
            min-width: 0; /* 重要：允许内容区域收缩 */
            min-height: 100vh;
            background: transparent;
            padding: 0;
            overflow-x: auto; /* 允许水平滚动 */
        }

        .content-header {
            background: rgba(255, 255, 255, 0.9);
            backdrop-filter: blur(20px);
            border-bottom: 1px solid rgba(255, 255, 255, 0.2);
            padding: 1.25rem 2rem;
            margin-bottom: 2rem;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
            position: sticky;
            top: 0;
            z-index: 100;
        }

        .content-header h1 {
            font-size: 1.875rem;
            font-weight: 700;
            color: #1e293b;
            margin: 0;
            background: linear-gradient(135deg, #1e293b, #64748b);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        .content-body {
            padding: 2rem 2rem 2rem;
            width: 100%;
            max-width: none; /* 移除最大宽度限制 */
        }

        /* 移动端响应式 */
        @media (max-width: 768px) {
            .admin-container {
                position: relative;
            }
            
            .sidebar {
                position: fixed;
                top: 0;
                left: 0;
                transform: translateX(-100%);
                width: 300px;
                min-width: 300px;
                max-width: 300px;
                box-shadow: none;
                z-index: 9999;
            }
            
            .sidebar.show {
                transform: translateX(0);
                box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
            }
            
            .main-content {
                width: 100%;
                margin-left: 0;
            }

            .content-header {
                padding: 1rem 1.5rem;
                margin-bottom: 1.5rem;
            }

            .content-body {
                padding: 1.5rem 1.5rem 1.5rem;
            }

            .mobile-toggle {
                display: block;
            }
        }

        /* 平板和大屏幕优化 */
        @media (min-width: 769px) {
            .mobile-toggle {
                display: none;
            }

            /* 超宽屏优化 */
            @media (min-width: 1920px) {
                :root {
                    --sidebar-width: 320px;
                }
            }

            /* 中等宽屏优化 */
            @media (min-width: 1400px) and (max-width: 1919px) {
                :root {
                    --sidebar-width: 300px;
                }
            }

            /* 标准宽屏优化 */
            @media (min-width: 1200px) and (max-width: 1399px) {
                :root {
                    --sidebar-width: 280px;
                }
            }

            /* 小宽屏优化 */
            @media (min-width: 992px) and (max-width: 1199px) {
                :root {
                    --sidebar-width: 260px;
                }
                
                .nav-link {
                    font-size: 0.9rem;
                    padding: 0.75rem 0.875rem;
                }
            }

            /* 窄屏优化 */
            @media (min-width: 769px) and (max-width: 991px) {
                :root {
                    --sidebar-width: 240px;
                }
                
                .nav-link {
                    font-size: 0.875rem;
                    padding: 0.75rem 0.75rem;
                }
                
                .nav-link i {
                    margin-right: 0.625rem;
                    font-size: 1rem;
                }
            }
        }

        /* 移动端切换按钮 */
        .mobile-toggle {
            position: fixed;
            top: 1rem;
            left: 1rem;
            z-index: 10000;
            background: linear-gradient(135deg, #0891b2, #0d9488);
            color: white;
            border: none;
            border-radius: 0.75rem;
            padding: 0.75rem;
            font-size: 1.25rem;
            box-shadow: 0 4px 12px rgba(8, 145, 178, 0.3);
            transition: all 0.2s ease;
            display: none;
        }

        .mobile-toggle:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(8, 145, 178, 0.4);
        }

        /* 确保 container-fluid 能够正常工作 */
        .container-fluid {
            width: 100%;
            max-width: none !important;
            padding-left: 0;
            padding-right: 0;
        }

        /* Bootstrap 行和列的优化 */
        .row {
            margin-left: 0;
            margin-right: 0;
        }

        .row > * {
            padding-left: 0.75rem;
            padding-right: 0.75rem;
        }

        /* 分页组件样式优化 */
        .pagination {
            margin: 0;
            gap: 0.25rem;
        }

        .pagination .page-item {
            margin: 0;
        }

        .pagination .page-link {
            border: 1px solid #e5e7eb;
            color: #6b7280;
            background-color: #ffffff;
            padding: 0.5rem 0.75rem;
            font-size: 0.875rem;
            font-weight: 500;
            border-radius: 0.5rem;
            transition: all 0.2s ease;
            display: flex;
            align-items: center;
            justify-content: center;
            min-width: 40px;
            min-height: 40px;
        }

        .pagination .page-link:hover {
            background-color: #f9fafb;
            border-color: #d1d5db;
            color: #374151;
            transform: translateY(-1px);
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }

        .pagination .page-item.active .page-link {
            background: linear-gradient(135deg, #0891b2, #0d9488);
            border-color: #0891b2;
            color: #ffffff;
            box-shadow: 0 4px 12px rgba(8, 145, 178, 0.3);
        }

        .pagination .page-item.disabled .page-link {
            color: #d1d5db;
            background-color: #f9fafb;
            border-color: #f3f4f6;
            cursor: not-allowed;
        }

        .pagination .page-item.disabled .page-link:hover {
            transform: none;
            box-shadow: none;
        }

        /* 修复 Laravel 分页箭头样式 */
        nav[aria-label="Pagination Navigation"] svg {
            width: 1rem !important;
            height: 1rem !important;
        }
        
        nav[aria-label="Pagination Navigation"] .relative.inline-flex.items-center {
            padding: 0.5rem !important;
            border-radius: 0.375rem !important;
            border: 1px solid #e5e7eb !important;
            background-color: #ffffff !important;
            color: #6b7280 !important;
            transition: all 0.2s ease !important;
        }
        
        nav[aria-label="Pagination Navigation"] .relative.inline-flex.items-center:hover {
            background-color: #f9fafb !important;
            border-color: #d1d5db !important;
            color: #374151 !important;
        }
        
        nav[aria-label="Pagination Navigation"] .relative.inline-flex.items-center[aria-current="page"] {
            background: linear-gradient(135deg, #0891b2, #0d9488) !important;
            border-color: #0891b2 !important;
            color: #ffffff !important;
        }

        /* 分页信息文本样式 */
        .pagination-info {
            font-size: 0.875rem;
            color: #6b7280;
            margin-bottom: 1rem;
            text-align: center;
        }

        /* 响应式分页 */
        @media (max-width: 576px) {
            .pagination .page-link {
                padding: 0.375rem 0.5rem;
                font-size: 0.75rem;
                min-width: 32px;
                min-height: 32px;
            }

            .pagination .page-item:not(.active):not(.disabled) {
                display: none;
            }

            .pagination .page-item.active,
            .pagination .page-item.disabled,
            .pagination .page-item:first-child,
            .pagination .page-item:last-child,
            .pagination .page-item:nth-child(2),
            .pagination .page-item:nth-last-child(2) {
                display: block;
            }
        }
    </style>

    @stack('styles')
</head>
<body>
    <div class="admin-container">
        <!-- 移动端切换按钮 -->
        <button class="mobile-toggle" onclick="toggleSidebar()">
            <i class="fas fa-bars"></i>
        </button>

        <!-- 侧边栏 -->
        <nav class="sidebar" id="sidebar">
            <div class="sidebar-header">
                <h5>{{ site_name() }}</h5>
                <small>权限管理系统</small>
            </div>
            
            <div class="sidebar-nav">
                <ul class="nav flex-column">
                    <li class="nav-item">
                        <a class="nav-link {{ request()->routeIs('admin.dashboard') ? 'active' : '' }}" href="{{ route('admin.dashboard') }}">
                            <i class="fas fa-tachometer-alt"></i>
                            <span>仪表盘</span>
                        </a>
                    </li>
                    
                    <div class="nav-divider"></div>
                    
                    @can('view-users')
                    <li class="nav-item">
                        <a class="nav-link {{ request()->routeIs('admin.users.*') ? 'active' : '' }}" href="{{ route('admin.users.index') }}">
                            <i class="fas fa-users"></i>
                            <span>用户管理</span>
                        </a>
                    </li>
                    @endcan
                    
                    @can('view-roles')
                    <li class="nav-item">
                        <a class="nav-link {{ request()->routeIs('admin.roles.*') ? 'active' : '' }}" href="{{ route('admin.roles.index') }}">
                            <i class="fas fa-user-tag"></i>
                            <span>角色管理</span>
                        </a>
                    </li>
                    @endcan
                    
                    @can('view-permissions')
                    <li class="nav-item">
                        <a class="nav-link {{ request()->routeIs('admin.permissions.*') ? 'active' : '' }}" href="{{ route('admin.permissions.index') }}">
                            <i class="fas fa-key"></i>
                            <span>权限管理</span>
                        </a>
                    </li>
                    @endcan
                    
                    @can('view-organizations')
                    <li class="nav-item">
                        <a class="nav-link {{ request()->routeIs('admin.organizations.*') ? 'active' : '' }}" href="{{ route('admin.organizations.index') }}">
                            <i class="fas fa-building"></i>
                            <span>组织管理</span>
                        </a>
                    </li>
                    @endcan
                    
                    <div class="nav-divider"></div>
                    
                    @can('view-system-settings')
                    <li class="nav-item">
                        <a class="nav-link {{ request()->routeIs('admin.system-settings.*') ? 'active' : '' }}" href="{{ route('admin.system-settings.index') }}">
                            <i class="fas fa-cog"></i>
                            <span>系统设置</span>
                        </a>
                    </li>
                    @endcan
                    
                    <div class="nav-divider"></div>
                    
                    <li class="nav-item">
                        <a class="nav-link" href="{{ route('logout') }}" 
                           onclick="event.preventDefault(); document.getElementById('logout-form').submit();">
                            <i class="fas fa-sign-out-alt"></i>
                            <span>退出登录</span>
                        </a>
                        <form id="logout-form" action="{{ route('logout') }}" method="POST" class="d-none">
                            @csrf
                        </form>
                    </li>
                </ul>
            </div>
        </nav>

        <!-- 主内容区域 -->
        <main class="main-content">
            <div class="content-body">
                @yield('content')
            </div>
        </main>
    </div>

    <script>
        function toggleSidebar() {
            const sidebar = document.getElementById('sidebar');
            sidebar.classList.toggle('show');
        }

        // 点击页面其他地方关闭侧边栏（移动端）
        document.addEventListener('click', function(event) {
            const sidebar = document.getElementById('sidebar');
            const toggle = document.querySelector('.mobile-toggle');
            
            if (window.innerWidth <= 768) {
                if (!sidebar.contains(event.target) && !toggle.contains(event.target)) {
                    sidebar.classList.remove('show');
                }
            }
        });

        // 窗口大小改变时的处理
        window.addEventListener('resize', function() {
            const sidebar = document.getElementById('sidebar');
            if (window.innerWidth > 768) {
                sidebar.classList.remove('show');
            }
        });
    </script>

    @stack('scripts')
</body>
</html>